//
//  BaseTabBarController.m
//  liveFrame
//
//  Created by apple on 16/7/12.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "BaseTabBarController.h"
#import "BaseNavgationController.h"
#import "BaseTabBar.h"
#import "UIImage+JLXXImage.h"
@interface BaseTabBarController ()<BaseTabBarDelegate>

@end



@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    //自定义tabBar
    [self setUpTabBar];

}

//设置导航条的标题，分栏的标题。图片。等
#pragma mark - 添加一个子控制器
- (void)addChildControllerWithControllerName:(NSString *)controllerName normaImage:(NSString *)normalImageName selectedImage:(NSString *)selectedImageName navTitle:(NSString *)title tabBarTitle:(NSString *)tabBarTitle isRequireNavgation:(BOOL)isRequire
{
    Class class = NSClassFromString(controllerName);
    UIViewController *viewController = [[class alloc]init];
    viewController.tabBarItem.title = tabBarTitle;
    viewController.tabBarItem.image = [UIImage imageWithOriginalName:normalImageName];
    viewController.tabBarItem.selectedImage = [UIImage imageWithOriginalName:selectedImageName];
    if (isRequire)
    {
        BaseNavgationController *nav = [[BaseNavgationController alloc] initWithRootViewController:viewController];
        [self addChildViewController:nav];
    }else{
        [self addChildViewController:viewController];
    }
}

#pragma mark - 设置tabBar
- (void)setUpTabBar
{
    BaseTabBar *tabBar = [[BaseTabBar alloc]init];
    tabBar.baseDelegate = self;
    [self setValue:tabBar forKeyPath:@"tabBar"];
}

-(void)baseTabBar:(BaseTabBar *)tabBar didClickCenterButton:(UIButton *)button{
    if (self.clickCenter) {
        self.clickCenter();
    }
}

-(void)dealloc{
#ifdef DEBUG
    NSLog(@"%@",self);
#endif
}

@end
